package com.maxlen.common.utils;

/**
 * 返回数据枚举
 */
public enum ResultCode {
    /* 成功 */
    SUCCESS(200, null),
    SUCCESS_login(200, "用户登录成功"),
    SUCCESS_logout(200, "用户退出成功"),

    /* 默认失败 */
    COMMON_FAIL(999, "失败"),

    /* 参数错误：1000～1999 */
    PARAM_NOT_VALID(1001, "参数无效"),
    PARAM_IS_BLANK(1002, "参数为空"),
    PARAM_TYPE_ERROR(1003, "参数类型错误"),
    SMS_CODE_ERROR(1004, "操作频繁，请刷新重试"),

    /* 用户错误 */
    USER_NOT_LOGIN(2001, "用户未登录"),
    USER_ACCOUNT_EXPIRED(2002, "登录已过期"),
    USER_CREDENTIALS_ERROR(2003, "账号密码错误"),
    USER_CREDENTIALS_EXPIRED(2004, "密码过期"),
    USER_ACCOUNT_DISABLE(2005, "账号不可用"),
    USER_ACCOUNT_LOCKED(2006, "账号被锁定"),
    USER_ACCOUNT_NOT_EXIST(2007, "账号不存在"),
    USER_ACCOUNT_ALREADY_EXIST(2008, "账号已存在"),
    USER_ACCOUNT_USE_BY_OTHERS(2009, "账号下线"),
    USER_REGISTER_CODE_ERROR(2010, "验证码错误"),
    USER_REGISTER_CODE_OVERDUE(2011, "验证码过期"),
    USER_REGISTER_USERNAME_EXIST(2012, "用户名已存在"),
    USER_REGISTER_PHONE_EXIST(2013, "手机号已存在"),
    USER_REGISTER_EMAIL_EXIST(2014, "邮箱已存在"),
    USER_GITEE_EXIST(2014, "令牌异常"),
    USER_ADDRESS_ERROR(2014, "要取消默认地址，请添加其他地址"),

    /* 业务错误 */
    NO_PERMISSION(3001, "当前账号没有此权限"),

    /* 库存错误 */
    NO_STOCK(4001, ":商品没有库存了"),

    /**
     * 订单错误
     */
    CREATE_ORDER_ERROR(5001, "订单创建异常"),
    ORDER_WAIT_SEND(5002, "订单商品正待发货中不可删除"),
    ORDER_SEND(5002, "订单商品正发货中中不可删除"),
    RECEIVE_COUPON_ERROR(5003, "领取优惠券失败"),

    /**
     * 购物车
     */
    CHECK_ONE_TRUE(6001, "请至少选择一件商品"),
    CART_SERVICE_ERROR(6999, "购物车服务异常"),

    /**
     * 会员
     */
    MEMBER_SERVICE_ERROR(7999, "会员服务异常"),

    /**
     * 优惠券
     */
    COUPON_NO_CATEGORY(8001, "没有分类参数"),
    COUPON_NO_SPU(8002, "没有商品参数"),
    COUPON_NO_ATTR(8003, "没有指定参数"),
    COUPON_OVERTIME(8004, "优惠券过期"),


    /**
     * 商品
     */
    PRODUCT_SERVICE_ERROR(9999, "商品服务异常"),

    ;


    private Integer code;
    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 根据code获取message
     *
     * @param code
     * @return
     */
    public static String getMessageByCode(Integer code) {
        for (ResultCode ele : values()) {
            if (ele.getCode().equals(code)) {
                return ele.getMessage();
            }
        }
        return null;
    }
}
